﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using System.Windows;
using Autofac;
using Autofac.Builder;
using Autofac.Extras.CommonServiceLocator;
#if NET40
using Autofac.Extras.DynamicProxy2;
#else
using Autofac.Extras.DynamicProxy;
#endif
using Log.Common;
using Log.Common.Log4Net;
using Mvvm.Common;
using Mvvm.Common.Aop;
using Mvvm.Common.WindowExtensions;
using WPFCommon.Test.ViewModel;
#if NET40
using Microsoft.Practices.ServiceLocation;
#else
using CommonServiceLocator;
#endif

namespace WPFCommon.Test
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
#if NET40
        private  void App_OnStartup(object sender, StartupEventArgs e)
#else   
        private async void App_OnStartup(object sender, StartupEventArgs e)
#endif
        {
            var container = InitBuilder();
            ServiceLocator.SetLocatorProvider(()=>new AutofacServiceLocator(container));
            var log = ServiceLocator.Current.GetInstance<ILog>();
            log.Info("程序启动中...");
            var mainModel = container.Resolve<MainViewModel>();
#if NETCOREAPP3_1
var task= mainModel.AopReturnTest();
Debug.WriteLine("ddddd");
await task;
#endif
            
         
            mainModel.CreateWindow<MainWindow>().RegisterTitle(isAllowDoubleClick:true).ShowDialog();
        }

        private IContainer InitBuilder()
        {
            ContainerBuilder builder=new ContainerBuilder();
            builder.RegisterAopInterceptor();
          
            builder.RegisterType<Log4NetLog>().As<ILog>().SingleInstance();
            builder.RegisterType<MainViewModel>().RegisterClassInterceptors();
            return builder.Build();
        }

     
      
    }
}
